<?php
/**
 *	Tool Index.
 *
 *	Copyright (c) 2008 Christian Würker (ceus-media.de)
 *
 *	This program is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.
 *
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *	@package		krypton.tools
 *	@author			Christian Würker <Christian.Wuerker@CeuS-Media.de>
 *	@copyright		2007-2009 Christian Würker
 *	@license		http://www.gnu.org/licenses/gpl-3.0.txt GPL 3
 *	@link			http://code.google.com/p/cmclasses/
 *	@since			14.02.2007
 *	@version		0.6
 */
import( 'de.ceus-media.folder.Lister' );
import( 'de.ceus-media.ui.Template' );
import( 'de.ceus-media.ui.html.Tag' );
/**
 *	Validator for Predicates on Strings.
 *	@package		krypton.tools
 *	@uses			Folder_Lister
 *	@uses			UI_Template
 *	@uses			UI_HTML_Tag
 *	@author			Christian Würker <Christian.Wuerker@CeuS-Media.de>
 *	@copyright		2007-2009 Christian Würker
 *	@license		http://www.gnu.org/licenses/gpl-3.0.txt GPL 3
 *	@link			http://code.google.com/p/cmclasses/
 *	@since			14.02.2007
 *	@version		0.6
 */
class Index
{
	public static $pathCss	= '//css.ceusmedia.com/';
	public static $pathJs	= '//js.ceusmedia.com/';

	/**
	 *	Constructor, shows HTML Index.
	 *	@access		public
	 *	@return		void
	 */
	public function __construct()
	{
		$labels	= parse_ini_file( ".index/config.ini", TRUE );
		$index		= Folder_Lister::getMixedList( "./" );
		$list	= array();
		foreach( $index as $entry )
		{
			$fileName	= $entry->getFilename();
			if( $fileName == "nbproject" )
				continue;
			$description	= isset( $labels[$fileName]['description'] ) ? "<br/>".$labels[$fileName]['description'] : "";
			$tags			= "";
			if( isset( $labels[$fileName]['tags'] ) )
			{
				$tagList	= explode( ",", $labels[$fileName]['tags'] );
				foreach( $tagList as $id => $tag )
					$tagList[$id]	= '<span class="tag">'.$tag.'</span>';
				$tags	= implode( ", ", $tagList );
				$tags	= '<br/><span class="tags">Tags: '.$tags.'</span>';

			}
			if( $fileName	== "index.php5" )
				continue;
			if( preg_match( "@^(catch|_|\.)@", $fileName ) )
				continue;
			$link	= UI_HTML_Tag::create( "a", $fileName, array( 'href' => "./".$fileName."/" ) );
			$list[$fileName]	= UI_HTML_Tag::create( "li", $link.$description.$tags, isset( $labels[$fileName]['status'] ) ? array( 'class' => $labels[$fileName]['status'] ) : array() );
		}
		ksort( $list );
		$list		= UI_HTML_Tag::create( "ul", implode( "\n", $list ) );
		$template	= new UI_Template( '.index/template.html' );
		$template->addElement( 'list', $list );
		$template->addElement( 'pathCss', self::$pathCss );
		$template->addElement( 'pathJs', self::$pathJs );
		print( $template->create() );
		die;
	}
}
?>
